package com.华为OD.牛客;

import java.util.ArrayList;
import java.util.Scanner;

public class HJ43迷宫问题 {
    public static int[][] map;
    public static ArrayList<String> path = new ArrayList<>();
    public static ArrayList<String>ans;
    public static void dps(int i,int j){
        int nr=map.length,nl=map[0].length;
        if(i<0||i>=nr||j<0||j>=nl||map[i][j]==1)
            return;
        if(i==nr-1&&j==nl-1){
            if(ans==null||ans.size()>path.size())
                ans = new ArrayList<>(path);
        }
        String s = "("+i+","+j+")";
        if(path.contains(s))
            return;
        path.add(s);
        dps(i+1,j);
        dps(i,j+1);
        dps(i-1,j);
        dps(i,j-1);
        path.remove(path.size()-1);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int nr = in.nextInt(),nl = in.nextInt();
        map = new int [nr][nl];
        for(int i =0;i<nr;i++)
            for(int j =0;j<nl;j++)
                map[i][j] = in.nextInt();
        dps(0,0);
        for(int i =0;i<ans.size();i++){
            System.out.println(ans.get(i));
        }
        System.out.println("("+(nr-1)+","+(nl-1)+")");
    }
}
